<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";

import { position, positionDel } from "@/http/api";
export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [],
      comArr: [],
      queryData: {
        enterprise_name: "",
        position_name: "",
        page: 1,
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    deleteFn(row) {
      ElMessageBox.confirm("确定删除选择的岗位吗?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        const { data } = await positionDel({
          enterprise_position_id: row.enterprise_position_id,
        });
        if (data.code == 1) {
          ElMessage({
            type: "success",
            message: "删除成功",
          });
          this.getData();
        }
      });
    },
    detailFn(row) {
      this.$router.push({
        path: "/sendWorkDetail",
        query: { id: row.enterprise_position_id, page: this.queryData.page },
      });
    },

    getData() {
      position(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
    addFn() {
      this.$router.push({ path: "/sendWorkAdd" });
    },
  },
  mounted() {},
  async created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.comArr = await this.$getCate.getComList();

    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>岗位列表（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft">
          <btn value="新增" @ok="addFn"></btn>
        </div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-select
                v-model="queryData.enterprise_name"
                filterable
                clearable
                @change="getData"
                placeholder="请输入发布企业"
              >
                <el-option
                  v-for="item in comArr"
                  :key="item.enterprise_id"
                  :label="item.enterprise_name"
                  :value="item.enterprise_name"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.position_name"
                placeholder="请输入岗位名称"
              />
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="enterprise_name"
          show-overflow-tooltip
          label="发布账号"
        />
        <el-table-column
          prop="enterprise_name"
          show-overflow-tooltip
          label="发布来源"
        >
          <template #default="{ row }">
            <el-tag v-if="row.position_create_type == 1" type="success"
              >企业发布</el-tag
            >
            <el-tag v-if="row.position_create_type == 2" type="info"
              >管理员发布</el-tag
            >
            <el-tag v-if="row.position_create_type == 3">小程序发布</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="position_name"
          show-overflow-tooltip
          label="岗位职务"
        />
        <el-table-column
          prop="watercraft_name"
          show-overflow-tooltip
          label="船名"
        >
          <template #default="{ row }">
            {{ row.watercraft_name || "- -" }}
          </template>
        </el-table-column>
        <el-table-column
          width="100"
          prop="zprs"
          show-overflow-tooltip
          label="招聘人数"
        />
        <el-table-column
          prop="workMoney"
          show-overflow-tooltip
          label="薪资待遇"
        >
          <template #default="{ row }">
            <div v-if="row.start_monry == '0'">面议</div>
            <div v-else>
              {{ row.start_monry }}~{{ row.end_monry
              }}{{ row.unit == 1 ? "元" : "美元" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          width="180"
          show-overflow-tooltip
          label="创建时间"
        />
        <el-table-column prop="Name" width="120" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div class="greenText ctrlText" @click="detailFn(row)">详情</div>
              <div class="redText ctrlText" @click="deleteFn(row)">删除</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
